/****************
 *************
 *
 * User: QinTaoLin *
 * Time: 2017-01-15 *
 * Project: 导航栏切换*
 * 
 *************
****************/
// var loading = document.getElementsByClassName("loading");
var headerNav = document.getElementById("headerNav");
var headerNavLinks = document.getElementsByClassName("headerNav-link");
var pageContentList = document.getElementsByClassName("pageContentList");
var userImage = document.getElementById("userImage");
var weixin = document.getElementsByClassName("weixin");

userImage.addEventListener('mouseover', () => {
  weixin[0].classList.add("active");
});

userImage.addEventListener('mouseout', () => {
  weixin[0].classList.remove("active");
});

//朗读事件
// const utterance = new SpeechSynthesisUtterance();
// utterance.lang = 'zh-CN'; // 语种，默认等同于html标签的lang属性，如果此属性未设置，则等同于用户代理（浏览器）的设置
// utterance.pitch = 1; // 音高，0 - 1，默认1
// utterance.rate = 0.95; // 语速，0.1 - 10，默认1
// utterance.volumn = 1; // 音量，0 - 1，默认1
// utterance.text = 'Hello World';


/* 选择内容函数 */
var pageContentListFunc = (navType) => {
  for (let i = 0; i < pageContentList.length; i++) {
    var pageContentListType = pageContentList[i].getAttribute('nav-type');
    pageContentList[i].classList.remove('active');
    if (pageContentListType === navType) {
      pageContentList[i].classList.add('active');
    }
  }
};

/* 导航栏点击事件 */
headerNav.addEventListener('click', e => {
  // speechSynthesis.speak(utterance);
  for (let i = 0; i < headerNavLinks.length; i++) {
    headerNavLinks[i].classList.remove('active');
  }
  e.target.classList.add('active');
  pageContentListFunc(e.target.getAttribute('nav-type'));
});

/* 背景音乐 */
let play = false;
var audio = document.getElementById("audio");
let timer;

const loadingPage = () => {
  timer = setInterval(() => {
    console.log(audio.readyState);
    if (audio.readyState >= 2) {
      // loading[0].classList.add('is-hidden');
      clearInterval(timer);
    }
  }, 3000);
};

window.onload = loadingPage();

// audio.play();
var headerMusic = document.getElementById("headerMusic");
headerMusic.addEventListener('click', (e) => {
  headerMusic.classList.toggle('is-active');
  this.play = !this.play;
  this.play ? audio.play() : audio.pause();
});

/* 简历导航 */
// var resumeBottons = document.getElementsByClassName('pageContentList-resumeBox-button');
// var resumeTextBox = document.getElementsByClassName('resumeTextBox');
// var resumeCommetContent = (id) => {
//   var commetcontent = document.getElementById(id);
//   resumeTextBox[0].scrollTop = commetcontent.offsetTop - 40;
// }

// for (let i = 0; i < resumeBottons.length; i++) {
//   resumeBottons[i].addEventListener('click', (e) => {
//     for (let i = 0; i < resumeBottons.length; i++) {
//       resumeBottons[i].classList.remove('active');
//     }
//     e.target.classList.add('active');
//     resumeCommetContent(e.target.getAttribute('resume-type'));
//   });
// }

